package com.yl.student.util;

import javax.servlet.http.HttpServletRequest;

public class BasePathUtil {
    public static String getBasePath(HttpServletRequest request) {
        //协议
        String scheme = request.getScheme();
        //服务名：localhost
        String serverName = request.getServerName();
        //端口号
        int serverPort = request.getServerPort();
        //项目路径：ssm_student
        String contextPath = request.getContextPath();
        if(serverPort == 80){
            return scheme + "://" + serverName + contextPath + "/";
        }else{
            return scheme + "://" + serverName + ":" + serverPort + contextPath + "/";
        }
    }
}
